package com.neymar.controller;


import com.neymar.entity.Company;
import com.neymar.entity.User;
import com.neymar.logEnum.ObjectionTypeEnum;
import com.neymar.mapper.CompanyMapper;
import com.neymar.service.CompanyService;
import com.neymar.service.LogService;
import com.neymar.service.UserService;
import com.neymar.vo.CompanyVO;
import com.neymar.vo.R;
import com.neymar.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 公司表 前端控制器
 * </p>
 *
 * @author neymar
 * @since 2021-06-02
 */
@RestController
@RequestMapping("/company")
@Api(tags = {"公司信息操作接口"})
public class CompanyController {
    @Autowired
    private CompanyService companyService;

    @Autowired
    private LogService logService;

    @ApiOperation("保存公司信息")
    @PostMapping("/save/{operatorId}")
    public R save(@RequestBody Company company,
                  @PathVariable("operatorId") String operatorId) {
        int flag = companyService.save(company);
        if (flag != 0) {
            logService.save(operatorId, 1, 6);
            return R.ok();
        }
        return R.fail();
    }

    @ApiOperation("根据ID查找公司信息")
    @GetMapping("/find/{companyId}/{operatorId}")
    public R findCompanyById(@PathVariable("companyId") String companyId,
                             @PathVariable("operatorId") String operatorId) {
        logService.save(operatorId, 4, 6);
        return R.ok(companyService.findCompanyById(companyId));
    }

    @ApiOperation("根据ID删除公司信息")
    @DeleteMapping("/delete/{companyId}/{operatorId}")
    public R deleteCompanyById(@PathVariable("companyId") String companyId,
                               @PathVariable("operatorId") String operatorId) {
        int flag = companyService.deleteCompanyById(companyId);
        if (flag != 0) {
            logService.save(operatorId, 2, 6);
            return R.ok();
        }
        return R.fail();
    }

    @ApiOperation("根据公司ID修改公司信息")
    @PutMapping("/update/{operatorId}")
    public R updateCompanyById(@RequestBody Company company, @PathVariable("operatorId") String operatorId) {
        int flag = companyService.updateCompanyById(company);
        if (flag != 0) {
            logService.save(operatorId, 3, 6);
            return R.ok();
        }
        return R.fail();
    }

    @ApiOperation("[分页查询]根据公司名字模糊查询公司")
    @GetMapping("/findCompany/{current}/{size}/{name}/{operatorId}")
    public R findAllUser(@PathVariable("current") int current,
                         @PathVariable("size") int size,
                         @PathVariable("name") String name,
                         @PathVariable("operatorId") String operatorId) {
        logService.save(operatorId, 4, 6);
        return R.ok(companyService.findAllCompany(current, size, name));
    }

    @ApiOperation("[分页查询]根据公司ID查看该公司的所有招聘岗位的信息")
    @GetMapping("/findUsersDetails/{current}/{size}/{id}/{operatorId}")
    public R findAllUserDetails(@PathVariable("id") String id,
                                @PathVariable("current") int current,
                                @PathVariable("size") int size,
                                @PathVariable("operatorId") String operatorId) {
        logService.save(operatorId, 4, 6);
        return R.ok(companyService.findCompanyDetails(id, current, size));
    }

}

